package com.jiyi.activity.design;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;

import com.swift.base.ActivityBase;
import com.swift.maintenance.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DrawerActivity extends ActivityBase {

    @BindView(R.id.nv_menu)
    NavigationView nvMenu;
    @BindView(R.id.drawer_layout)
    DrawerLayout drawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer_navigage);
        ButterKnife.bind(this);

        nvMenu.setItemIconTintList(null);
        View head = nvMenu.getHeaderView(0);
        head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar snackbar = Snackbar.make(nvMenu, "你点击了头部", Snackbar.LENGTH_SHORT);
                snackbar.show();

            }
        });
        nvMenu.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Snackbar snackbar = Snackbar.make(nvMenu, "你点击了" + item.getTitle(), Snackbar.LENGTH_SHORT);
                snackbar.show();
                drawerLayout.closeDrawer(GravityCompat.START);
                return false;
            }
        });
    }

    @Override
    public void onBackPressed() {
        if (drawerLayout.isDrawerOpen(GravityCompat.START))
        {
            drawerLayout.closeDrawer(GravityCompat.START);
        }
        else
        {
            super.onBackPressed();
        }
    }
}
